package com.xy.bizportdemo.database.entity;

import android.content.ContentValues;
import android.database.Cursor;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by XIAOYUAN on 2016/11/24.
 */

public class ConversationItem {
    public static final int STATE_ENTERPRISE = 0;
    public static final int STATE_PERSONAL = 1;
    public static final int STATE_BLOCK = 2;

    public long id;
    public int msgCount;
    public String lastMsg;
    public String number;
    public long lastDate;
    public int state;


    private Map<String, Object> extendMap;

    public ConversationItem() {

    }

    public Map<String, Object> setExtendMap(String key, Object obj) {
        if (extendMap == null){
            extendMap = new HashMap<String, Object>();
        }
        if (key != null && !"".equalsIgnoreCase(key) && obj != null){
            extendMap.put(key, obj);
        }
        return extendMap;
    }

    public Map<String, Object> getExtendMap() {
        return extendMap;
    }

    public ConversationItem setCount(int count) {
        this.msgCount = count;
        return this;
    }

    public ConversationItem setBody(String body) {
        this.lastMsg = body;
        return this;
    }

    public ConversationItem setDate(String date) {
        this.lastDate = Long.parseLong(date);
        return this;
    }

    public ConversationItem setNumber(String number) {
        this.number = number;
        return this;
    }

    public ConversationItem setState(int state) {
        this.state = state;
        return this;
    }

    public ConversationItem(Cursor cursor) {
        this.id = Long.parseLong(cursor.getString(cursor.getColumnIndex(SmsDBTableConversation.KEY_ID)));
        this.msgCount = cursor.getInt(cursor.getColumnIndex(SmsDBTableConversation.KEY_MSG_COUNT));
        this.lastMsg = cursor.getString(cursor.getColumnIndex(SmsDBTableConversation.KEY_LAST_MSG));
        this.number = cursor.getString(cursor.getColumnIndex(SmsDBTableConversation.KEY_NUMBER));
        this.state = cursor.getInt(cursor.getColumnIndex(SmsDBTableConversation.KEY_STATE));
        this.lastDate = Long.parseLong(cursor.getString(cursor.getColumnIndex(SmsDBTableConversation.KEY_LAST_DATE)));
    }

    public ContentValues getContentValues() {
        ContentValues values = new ContentValues();

        values.put(SmsDBTableConversation.KEY_MSG_COUNT, this.msgCount);
        values.put(SmsDBTableConversation.KEY_LAST_MSG, this.lastMsg);
        values.put(SmsDBTableConversation.KEY_NUMBER, this.number);
        values.put(SmsDBTableConversation.KEY_STATE, this.state);
        values.put(SmsDBTableConversation.KEY_LAST_DATE, this.lastDate);

        return values;
    }
}
